<?php
/**
 * Auto Regenerate CSS & JS SleekPHP Plug-in.
 *
 * If DEBUG this plug-in automatically regenerates
 * CSS and JS-files for the current site's current style
 * on every page load.
 *
 * @subpackage Plugins
 */
Events::bind('BeforeOutput', 'SPAutoRegenerateCSSJS');

/**
 * Appends iframes which point to regenerate util
 *
 * @param string $output
 */
function SPAutoRegenerateCSSJS ($output) {
	if (DEBUG) {
		return str_replace('</body>', '
			<iframe style="display: none" src="' . WEBROOT . 'Utils/CodeMerger.php?site=' . SleekPHP::site()->getSite() . '&amp;style=' . SleekPHP::currentStyle() . '&amp;type=scss"></iframe>
			<iframe style="display: none" src="' . WEBROOT . 'Utils/CodeMerger.php?site=' . SleekPHP::site()->getSite() . '&amp;style=' . SleekPHP::currentStyle() . '&amp;type=js"></iframe>
			<iframe style="display: none" src="' . WEBROOT . 'Utils/CodeMerger.php?site=' . SleekPHP::site()->getSite() . '&amp;style=' . SleekPHP::currentStyle() . '&amp;type=js_head"></iframe>
		</body>', $output);
	}

	return $output;
}
